package com.yeyuanqi.hottop.untils;

import com.yeyuanqi.hottop.vo.BasicLineAndBarVO;
import com.yeyuanqi.hottop.vo.HotListVO;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 封装了一个用于生成基础折线图和柱状图所需数据格式的方法
 * @author yeyuanqi
 * @date 2022/01/22
 **/
@Component
public class BasicLineChartDataUtil {

    /**
     * 封装
     * @param hotlists 热搜数据列表
     * @return 基础折线图和柱状图数据格式
     */
    public BasicLineAndBarVO getBasicLineAndBarChartHotData(List<HotListVO> hotlists){
        BasicLineAndBarVO bdBasicLineVO = new BasicLineAndBarVO();
        List<String> topic = new ArrayList<>();
        List<Integer> hot = new ArrayList<>();
        List<String> url = new ArrayList<>();
        for (HotListVO hotlist : hotlists){
            topic.add(hotlist.getTopic());
            hot.add(hotlist.getHot());
            url.add(hotlist.getUrl());
        }
        bdBasicLineVO.setTopic(topic);
        bdBasicLineVO.setHot(hot);
        bdBasicLineVO.setUrl(url);
        return bdBasicLineVO;
    }
}
